package duoxiancheng;

/**
 * @Author Zhouchb
 * @Create 2022-03-2022/3/7 :18:07
 * @Description
 */
public class Likou {
}
//创建三个线程
class MyThread1 extends Thread {

    private Foo foo;
    private Runnable runnable;
    public MyThread1(Foo foo,Runnable runnable){
        this.foo = foo;
        this.runnable = runnable;
    }
    @Override
    public void run() {
        try {
            foo.first(runnable);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class MyThread2 extends Thread{

    private Foo foo;
    private Runnable runnable;
    public MyThread2(Foo foo,Runnable runnable){
        this.foo = foo;
        this.runnable = runnable;
    }
    @Override
    public void run() {
        try {
            foo.second(runnable);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


class MyThread3 extends Thread{

    private Foo foo;
    private Runnable runnable;
    public MyThread3(Foo foo,Runnable runnable){
        this.foo = foo;
        this.runnable = runnable;
    }
    @Override
    public void run() {
        try {
            foo.third(runnable);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

//创建测试类
class FooTest {

    public static void main(String[] args) throws InterruptedException {
        Foo foo = new Foo();

        Runnable a = new Runnable() {
            @Override
            public void run() {
                System.out.println("first");
            }
        };

        Runnable b = new Runnable() {
            @Override
            public void run() {
                System.out.println("second");
            }
        };

        Runnable c = new Runnable() {
            @Override
            public void run() {
                System.out.println("third");
            }
        };

        MyThread1 A = new MyThread1(foo,a);
        MyThread3 C = new MyThread3(foo,c);
        MyThread2 B = new MyThread2(foo,b);
        A.start();
        C.start();
        B.start();

    }
}
class Foo {

    public Foo() {

    }

    public void first(Runnable printFirst) throws InterruptedException {

        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
    }

    public void second(Runnable printSecond) throws InterruptedException {

        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
    }

    public void third(Runnable printThird) throws InterruptedException {

        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }
}